package com.作业.Day8;

import java.util.Scanner;

public class Homework2 {
    public static void main(String[] args) {
        Person1 person1 = new Person1();
        System.out.println("请输入年龄");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        try {
            person1.setAge(i);
        } catch (AgeException e) {
            e.printStackTrace();
        }
        System.out.println("输入成功");
    }
}
class Person1{
    int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
       if(age<1||age>10)
           throw new AgeException("年龄必须在1到10之间");
     else
         this.age=age;
}
}
class AgeException extends Exception{
    public AgeException(String message) {
        super(message);
    }
}